package io.jpress.module.theme.controller;

import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;
import io.jboot.web.directive.annotation.JFinalDirective;
import io.jboot.web.directive.base.JbootDirectiveBase;
import io.jpress.module.theme.model.Template;
import io.jpress.module.theme.service.TemplateService;

import javax.inject.Inject;


@JFinalDirective("myTheme")
public class MyThemeDirective extends JbootDirectiveBase {

    @Inject
    TemplateService templateService;

    @Override
    public void onRender(Env env, Scope scope, Writer writer) {

        Object id = getPara("id",scope);

        Template template = templateService.findById(id);
        scope.setLocal("template",template);

        renderBody(env,scope,writer);
    }

    @Override
    public boolean hasEnd() {
        return true;
    }
}
